import request from '@/config/axios'

// 中间库 VO
export interface MaterialInventorVO {
  id: number // 编号
  serialNo: string // 序列号
  batchNo: string // 批次号
  docNo: string // 工单号
  itemCode: string // 材料品号
  itemName: string // 材料品名
  itemSpecification: string // 材料规格
  itemDesc: string // 材料描述
  drawingNo: string // 材料图号
  unit: string // 单位
  materialType: string // 物料类型
  brand: string // 品牌
  qty: number // 数量
  mainImage: string // 主图
  status: number // 状态
  location:string
}

// 中间库 API
export const MaterialInventorApi = {
  // 查询中间库分页
  getMaterialInventorPage: async (params: any) => {
    return await request.get({ url: `/opticore/material-inventor/page`, params })
  },

  // 查询视图分页
  getMaterialViewPage: async (params: any) => {
    return await request.get({ url: `/opticore/material-inventor/pageView`, params })
  },

    // 查询中间库分页
    getMaterialInventorPageMid: async (params: any) => {
      return await request.get({ url: `/opticore/material-inventor/page-mid`, params })
    },

  // 查询中间库详情
  getMaterialInventor: async (id: number) => {
    return await request.get({ url: `/opticore/material-inventor/get?id=` + id })
  },

  // 新增中间库
  createMaterialInventor: async (data: MaterialInventorVO) => {
    return await request.post({ url: `/opticore/material-inventor/create`, data })
  },

  // 修改中间库
  updateMaterialInventor: async (data: MaterialInventorVO) => {
    return await request.put({ url: `/opticore/material-inventor/update`, data })
  },

  // 删除中间库
  deleteMaterialInventor: async (id: number) => {
    return await request.delete({ url: `/opticore/material-inventor/delete?id=` + id })
  },

  // 导出中间库 Excel  物料追溯
  exportMaterialInventor: async (params) => {
    return await request.download({ url: `/opticore/material-inventor/export-excel`, params })
  },

   // 导出中间库 Excel  中间库
   exportMaterialInventorMid: async (params) => {
    return await request.download({ url: `/opticore/material-inventor/export-excelmid`, params })
  },

  // 获取工单选中的中间库数据
  getOrderNodeDetailMaterialByDocNo: async (docNo: string) => {
    return await request.get({ url: `/opticore/fibers/order-node-detail-material/getByDocNo?docNo=` + docNo })
  },
// ==================== 子表（物料出入库记录） ====================

  // 获得物料出入库记录列表
  getMaterialStockListBySerialNo: async (serialNo) => {
    return await request.get({ url: `/opticore/material-inventor/material-stock/list-by-serial-no?serialNo=` + serialNo })
  },


    // 获得物料下所有序列号
    // getMaterialStockListBySerialNos: async (_itemCode,_itemSpecification) => {
    //   return await request.get({ url: `/opticore/material-inventor/material-stock/list-by-serial-no?itemCode=` })
    // },

    // 获得物料下所有序列号
getMaterialStockListBySerialNos: async (itemCode: string, itemSpecification: string) => {
  return await request.get({ 
    url: `/opticore/material-inventor/material-stock/list-by-serial-nos?itemCode=${itemCode}&itemSpecification=${itemSpecification}` 
  })
}
}
